# 分页
from django.core.paginator import Paginator

class Pages:
    def __init__(self, query_set, page_size):
        if page_size != None:
            self.page_size = page_size
            self.paginator = Paginator(query_set, page_size)
            self.page_total = self.paginator.num_pages
            self.exists = True
        else:
            self.paginator = None
            self.exists = False
            print('no valid args for pagenator')

    def is_exists(self):
        return self.exists

    def get(self, page_id):
        # page id from 1
        if self.is_exists():
            return self.paginator.get_page(page_id)
        else:
            print('paginator not exists')
